package Game;

import Character.Character;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Window extends JPanel implements ActionListener {
	Character p;
	public Image img;
	Timer time;

	public Window() {
		p = new Character();
		addKeyListener(new AL());
		setFocusable(true);
		ImageIcon background = new ImageIcon("C:/test.jpg");
		img = background.getImage();
		time = new Timer(5, this);
		time.start();
	}

	public void actionPerformed(ActionEvent e) {
		p.move();
		repaint();
	}

	public void paint(Graphics g) {
		super.paint(g);
		Graphics2D g2d = (Graphics2D) g;

		g2d.drawImage(img, 0, 0, null);
		g2d.drawImage(p.getImage(), p.getX(), p.getY(), null);
	}

	private class AL extends KeyAdapter {
		public void keyReleased(KeyEvent e) {
			p.keyReleased(e);
		}

		public void keyPressed(KeyEvent e) {
			p.keyPressed(e);
		}
	}
}